package com.ruix.app.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.ruix.app.R;
import com.ruix.app.adapter.superadapter.SuperAdapter;
import com.ruix.app.adapter.superadapter.internal.SuperViewHolder;
import com.ruix.app.model.ClassMenber;
import com.ruix.app.util.GlideUitl;

/**
 * Created by hadexs on 2017/4/26.
 */

public class ClassMenberAdapter extends SuperAdapter<ClassMenber> {

    private int greenColor = 0xFF15b86c;
    private int redColor = 0xFFff6565;
    private MenberActionListener listener;
    private boolean isTeacherCircle;

    public ClassMenberAdapter(Context context) {
        super(context, R.layout.item_class_menber);
    }

    @Override
    public void onBind(SuperViewHolder holder, int viewType, int position, final ClassMenber item) {

        // 设置右侧布局和左侧隐藏布局
//        View itemMidLayout = holder.getView(R.id.item_mid_layout);// item－中间布局
//        View itemRightLayout = holder.getView(R.id.item_right_layout);// item－右侧布局［＋删除按钮］
//        LinearLayout.LayoutParams midLps = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
//        itemMidLayout.setLayoutParams(midLps);
//        LinearLayout.LayoutParams rightLps = new LinearLayout.LayoutParams(rightItemWidth, LinearLayout.LayoutParams.MATCH_PARENT);
//        itemRightLayout.setLayoutParams(rightLps);

//        holder.setSimpleDraweeURI(R.id.sdv_user_avatar,item.getAvatar());
       ImageView view =  holder.getView(R.id.sdv_user_avatar);
        GlideUitl.showImageViewCircle(item.getAvatar(),view);

        holder.setText(R.id.tv_menber_name,item.getName());
        if (item.isDisplayRole()){
            String roleName = item.authorRoleValue(isTeacherCircle);
            if (!TextUtils.isEmpty(roleName)){
                holder.setText(R.id.tv_role_name,roleName);
            }
            holder.setVisibility(R.id.tv_role_name,View.VISIBLE);
        } else {
            holder.setVisibility(R.id.tv_role_name,View.GONE);
        }

        holder.setText(R.id.tv_menber_locate,item.getLocate()); //TODO
        holder.setText(R.id.tv_company,item.getCompany());
        if (item.isDisableSendMsg()) {
            holder.setText(R.id.tv_right_aciton, "解除禁言");
            holder.setBackgroundColor(R.id.tv_right_aciton, greenColor);
            holder.setVisibility(R.id.iv_disable_send_tag,View.VISIBLE);
        } else {
            holder.setText(R.id.tv_right_aciton, "禁言");
            holder.setBackgroundColor(R.id.tv_right_aciton, redColor);
            holder.setVisibility(R.id.iv_disable_send_tag,View.GONE);
        }
        holder.setOnClickListener(R.id.tv_right_aciton, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (item.isDisableSendMsg()) {
                    if (listener != null) {
                        listener.positivieRelieve(item);
                    }
                } else {
                    if (listener != null) {
                        listener.negativieDiable(item);
                    }
                }
            }
        });
    }

    public boolean isTeacherCircle() {
        return isTeacherCircle;
    }

    public void setTeacherCircle(boolean teacherCircle) {
        isTeacherCircle = teacherCircle;
    }

    public void setListener(MenberActionListener listener) {
        this.listener = listener;
    }

    public interface  MenberActionListener{
        void negativieDiable(ClassMenber menber); //禁言
        void positivieRelieve(ClassMenber menber); //解除

    }
}
